* This file is a re-replication of Gibler, Miller, and Little replication of Weeks (2008). 
* This is the second of two Weeks replication files.
* It focuses on replicating Weeks' results with different dyads and versions of the recip variable, based on different versions of the MID data.

clear
capture log close

log using "Weeks Analysis Replication.log", replace
set more off

***dmg: Get revisionist codes from the original data. CoW hasn't changed these codes in any iteration.  (We are currently
***dmg: going through the issues data more systematically.)
use "WeeksIO.dta", clear

drop ccodecow* abbrev1 abbrev2 cap_1 cap_2 milper_1 year milex_1 energy_1 irst_1 upop_1 tpop_1 milper_2 milex_2 energy_2 irst_2 upop_2 tpop_2 majpow1 majpow2 rlregion region1 region2 pol_rel tau_regi tau_glob s_un_reg s_un_glo s_wt_reg s_wt_glo rportu11 rportu12 rportu13 rportu14 rportu21 rportu22 rportu23 rportu24 rportu31 rportu32 rportu33 rportu34 rportu41 rportu42 rportu43 rportu44 rportn gportu11 gportu12 gportu13 gportu14 gportu21 gportu22 gportu23 gportu24 gportu31 gportu32 gportu33 gportu34 gportu41 gportu42 gportu43 gportu44 gportn rportw11 rportw12 rportw13 rportw14 rportw21 rportw22 rportw23 rportw24 rportw31 rportw32 rportw33 rportw34 rportw41 rportw42 rportw43 rportw44 rpordmax gportw11 gportw12 gportw13 gportw14 gportw21 gportw22 gportw23 gportw24 gportw31 gportw32 gportw33 gportw34 gportw41 gportw42 gportw43 gportw44 gpordmax tau_ld_1 tau_ld_2 s_ld_1 s_ld_2 alliance democ1 democ2 autoc1 autoc2 xrreg1 xrreg2 xrcomp1 xrcomp2 xropen1 xropen2 mono1 mono2 xconst1 xconst2 parreg1 parreg2 cent1 cent2 dem1 dem2 democlg1 democlg2 autoclg1 autoclg2 demlg1 demlg2 demchg1 demchg2 contig colcont colony1 colony2 distance dyaddur numstate numgps syscon sysmove1 sysmove5 sysmvgp1 sysmvgp5 cwongo cwongonm cwinit cwinitnm cwhost1 cwhost2 cwhostd cworig1 cworig2 cwjoanyi cwjoanyt cwjomidi cwjomidt cwmidnme cwstmo1 cwstday1 cwstyr1 cwstmo2 cwstday2 cwstyr2 cwendmo1 cwenddy1 cwendyr1 cwendmo2 cwenddy2 cwendyr2 cwsidea1 cwsidea2 cwrevis1 cwrevis2 cwrevt21 cwrevt12 cwrevt22 cwfatal1 cwfatex1 cwfatal2 cwfatex2 cwhiact1 cwhiact2 cwhiactd cwoutcm cwsettle cwfatald cwrecip cwnumst1 cwnumst2 cwnmmdnw cwnmmdal cwpceyrs cwpcedys cowrolea cowroleb _ccodematch cyear ccodepolity scode country _Geddes1 cyear_1 scode_1 country_1 personal_1 military_1 single_1 democ_1 autoc_1 polity_1 polity2_1 durable_1 xrreg_1 xrcomp_1 xropen_1 xconst_1 parreg_1 parcomp_1 exrec_1 exconst_1 polcomp_1 regtrans_1 demdum_1 threeyr_1 _ccodematch2 cyear2 ccodepolity2 scode2 _Geddes2 cyear_2 scode_2 country_2 personal_2 military_2 single_2 democ_2 autoc_2 polity_2 polity2_2 durable_2 xrreg_2 xrcomp_2 xropen_2 xconst_2 parreg_2 parcomp_2 exrec_2 exconst_2 polcomp_2 regtrans_2 demdum_2 threeyr_2 _ww ww _trade dtrade version dependa dependb imputed average versio01 _selectorate s1 s2 w1 w2 wovers1 wovers2 _polityIV_EUG1 abbrev_EUG1 cyear_EUG1 scode_EUG1 country_EUG1 flag_EUG1 fragment_EUG1 democ_EUG1 autoc_EUG1 polityIV polity2_EUG1 durable_EUG1 xrreg_EUG1 xrcomp_EUG1 xropen_EUG1 xconst_EUG1 parreg_EUG1 parcomp_EUG1 exrec_EUG1 exconst_EUG1 polcomp_EUG1 prior_EUG1 emonth_EUG1 eday_EUG1 eyear_EUG1 eprec_EUG1 interim_EUG1 bmonth_EUG1 bday_EUG1 byear_EUG1 bprec_EUG1 post_EUG1 change_EUG1 d3_EUG1 sf_EUG1 regtrans_EUG1 version_EUG1 _polityIV_EUG2 abbrev_EUG2 cyear_EUG2 scode_EUG2 country_EUG2 flag_EUG2 fragment_EUG2 democ_EUG2 autoc_EUG2 polityIV2 polity2_EUG2 durable_EUG2 xrreg_EUG2 xrcomp_EUG2 xropen_EUG2 xconst_EUG2 parreg_EUG2 parcomp_EUG2 exrec_EUG2 exconst_EUG2 polcomp_EUG2 prior_EUG2 emonth_EUG2 eday_EUG2 eyear_EUG2 eprec_EUG2 interim_EUG2 bmonth_EUG2 bday_EUG2 byear_EUG2 bprec_EUG2 post_EUG2 change_EUG2 d3_EUG2 sf_EUG2 regtrans_EUG2 version_EUG2 chaosPOL demdum1 purepers1 personal1 hybridpers1 hybrid1 single1 military1 monarch1 dynastic1 nondynastic1 dynastic1alt nondynastic1alt noinfo1 threeyr interregna interregnadem demdum1schultz other1 regimetype1 chaosPOL2 demdum2 demdumboth purepers2 personal2 hybridpers2 hybrid2 single2 military2 monarch2 dynastic2 nondynastic2 noinfo2 other2 regimetype2

rename cwkeynum dispnum
gen territory=1 if cwrevt11==1
gen policy=1 if  cwrevt11==2
gen regime=1 if  cwrevt11==3

collapse (max) territory policy regime, by (dispnum)

sort dispnum

save "WeeksRevCodes.dta", replace

***dmg: Now we have to get the recip DV from the original Weeks data because EUGene now uses MID4.1.
use "WeeksIO.dta", clear

drop abbrev1 abbrev2 cap_1 cap_2 milper_1 milex_1 energy_1 irst_1 upop_1 tpop_1 milper_2 milex_2 energy_2 irst_2 upop_2 tpop_2 majpow1 majpow2 rlregion region1 region2 pol_rel tau_regi tau_glob s_un_reg s_un_glo s_wt_reg s_wt_glo rportu11 rportu12 rportu13 rportu14 rportu21 rportu22 rportu23 rportu24 rportu31 rportu32 rportu33 rportu34 rportu41 rportu42 rportu43 rportu44 rportn gportu11 gportu12 gportu13 gportu14 gportu21 gportu22 gportu23 gportu24 gportu31 gportu32 gportu33 gportu34 gportu41 gportu42 gportu43 gportu44 gportn rportw11 rportw12 rportw13 rportw14 rportw21 rportw22 rportw23 rportw24 rportw31 rportw32 rportw33 rportw34 rportw41 rportw42 rportw43 rportw44 rpordmax gportw11 gportw12 gportw13 gportw14 gportw21 gportw22 gportw23 gportw24 gportw31 gportw32 gportw33 gportw34 gportw41 gportw42 gportw43 gportw44 gpordmax tau_ld_1 tau_ld_2 s_ld_1 s_ld_2 alliance democ1 democ2 autoc1 autoc2 xrreg1 xrreg2 xrcomp1 xrcomp2 xropen1 xropen2 mono1 mono2 xconst1 xconst2 parreg1 parreg2 cent1 cent2 dem1 dem2 democlg1 democlg2 autoclg1 autoclg2 demlg1 demlg2 demchg1 demchg2 contig colcont colony1 colony2 distance dyaddur numstate numgps syscon sysmove1 sysmove5 sysmvgp1 sysmvgp5 cwongo cwongonm cwinit cwinitnm cwhost1 cwhostd cworig1 cworig2 cwjoanyi cwjoanyt cwjomidi cwjomidt cwmidnme cwstmo1 cwstday1 cwstyr1 cwstmo2 cwstday2 cwstyr2 cwendmo1 cwenddy1 cwendyr1 cwendmo2 cwenddy2 cwendyr2 cwsidea1 cwsidea2 cwrevis1 cwrevis2 cwrevt21 cwrevt12 cwrevt22 cwfatal1 cwfatex1 cwfatal2 cwfatex2 cwhiact1 cwhiact2 cwhiactd cwoutcm cwsettle cwfatald cwrecip cwnumst1 cwnumst2 cwnmmdnw cwnmmdal cwpceyrs cwpcedys cowrolea cowroleb _ccodematch cyear ccodepolity scode country _Geddes1 cyear_1 scode_1 country_1 personal_1 military_1 single_1 democ_1 autoc_1 polity_1 polity2_1 durable_1 xrreg_1 xrcomp_1 xropen_1 xconst_1 parreg_1 parcomp_1 exrec_1 exconst_1 polcomp_1 regtrans_1 demdum_1 threeyr_1 _ccodematch2 cyear2 ccodepolity2 scode2 _Geddes2 cyear_2 scode_2 country_2 personal_2 military_2 single_2 democ_2 autoc_2 polity_2 polity2_2 durable_2 xrreg_2 xrcomp_2 xropen_2 xconst_2 parreg_2 parcomp_2 exrec_2 exconst_2 polcomp_2 regtrans_2 demdum_2 threeyr_2 _ww ww _trade dtrade version dependa dependb imputed average versio01 _selectorate s1 s2 w1 w2 wovers1 wovers2 _polityIV_EUG1 abbrev_EUG1 cyear_EUG1 scode_EUG1 country_EUG1 flag_EUG1 fragment_EUG1 democ_EUG1 autoc_EUG1 polityIV polity2_EUG1 durable_EUG1 xrreg_EUG1 xrcomp_EUG1 xropen_EUG1 xconst_EUG1 parreg_EUG1 parcomp_EUG1 exrec_EUG1 exconst_EUG1 polcomp_EUG1 prior_EUG1 emonth_EUG1 eday_EUG1 eyear_EUG1 eprec_EUG1 interim_EUG1 bmonth_EUG1 bday_EUG1 byear_EUG1 bprec_EUG1 post_EUG1 change_EUG1 d3_EUG1 sf_EUG1 regtrans_EUG1 version_EUG1 _polityIV_EUG2 abbrev_EUG2 cyear_EUG2 scode_EUG2 country_EUG2 flag_EUG2 fragment_EUG2 democ_EUG2 autoc_EUG2 polityIV2 polity2_EUG2 durable_EUG2 xrreg_EUG2 xrcomp_EUG2 xropen_EUG2 xconst_EUG2 parreg_EUG2 parcomp_EUG2 exrec_EUG2 exconst_EUG2 polcomp_EUG2 prior_EUG2 emonth_EUG2 eday_EUG2 eyear_EUG2 eprec_EUG2 interim_EUG2 bmonth_EUG2 bday_EUG2 byear_EUG2 bprec_EUG2 post_EUG2 change_EUG2 d3_EUG2 sf_EUG2 regtrans_EUG2 version_EUG2 chaosPOL demdum1 purepers1 personal1 hybridpers1 hybrid1 single1 military1 monarch1 dynastic1 nondynastic1 dynastic1alt nondynastic1alt noinfo1 threeyr interregna interregnadem demdum1schultz other1 regimetype1 chaosPOL2 demdum2 demdumboth purepers2 personal2 hybridpers2 hybrid2 single2 military2 monarch2 dynastic2 nondynastic2 noinfo2 other2 regimetype2

rename cwkeynum dispnum
sort ccodecow ccodecow2 year

save "WeeksRecips.dta", replace

***dmg: (cut) use "WeeksIO.dta", clear //This is from Weeks' website.
use "Weeks redux.dta", clear

***dmg: (cut) gen float recip=0
***dmg: (cut) replace recip=1 if cwhost2>1
***dmg: (cut) *cwhost2>1 picks up all instances in which the target responded with a militarized action

gen float capshare1=cap_1/(cap_1 + cap_2)
gen float logcaprat=log(cap_1/cap_2)

gen float ally=.
replace ally=1 if alliance==1
replace ally=1 if alliance==2
replace ally=1 if alliance==3
replace ally=0 if alliance==4

gen float majmaj=0
replace majmaj=1 if majpow1==1 &majpow2==1
gen float majmin=0
replace majmin=1 if majpow1==1 & majpow2==0
gen float minmaj=0
replace minmaj=1 if majpow1==0 & majpow2==1

***dmg: We chose not to use the issue codes for MIDs because these codes need to be redone.
***dmg: (cut) gen float revter=0
***dmg: (cut) replace revter=1 if cwrevt11==1
***dmg: (cut) gen float revpol=0
***dmg: (cut) replace revpol=1 if cwrevt11==2
***dmg: (cut) gen float revgov=0
***dmg: (cut) replace revgov=1 if cwrevt11== 3
***dmg: (cut) gen float revoth=0
***dmg: (cut) replace revoth=1 if cwrevt11==4

***dmg: (cut) replace dtrade=. if dtrade==-999
***dmg: (cut) replace s1=. if s1==-9
***dmg: (cut) replace s2=. if s2==-9
***dmg: (cut) replace w1=. if w1==-9
***dmg: (cut) replace w2=. if w2==-9

*fix contig variable
rename contig contig1
gen contig=0
replace contig=1 if contig1<6
*no missing values, so can use <

*mark bilateral dyads
***cut: gen bilateral=0
***cut: replace bilateral=1 if cwnumst1==1 & cwnumst2==1

***cut: label define regimetype1label 1 "democracy" 2 "personalist" 3 "military" 4 "single" 5 "hybrid" 6 "dynastic monarchy" 7 "non-dynastic monarchy" 8 "interregna" 9 "no info" 10 "other" 11 ""
***cut: label values regimetype1 regimetype1label

*variable marking whether initiator has an actual "regime"
gen int chaosEUG=0
***dmg: Rename polity variables to conform to original code
gen dem1=polity21
gen dem2=polity22 

replace chaosEUG=1 if dem1<-11

*generate Eugene variables just for comparison

gen demdum1EUG=.
replace demdum1EUG=0 if dem1<7
replace demdum1EUG=1 if dem1>6
***dmg: We changed the following from keeping missing values when coding democracies to coding it as no democracy.
***dmg: Polity IV missing values are not democracies.
replace demdum1EUG=0 if dem1==.

gen demdum2EUG= .
replace demdum2EUG=0 if dem2<7
replace demdum2EUG=1 if dem2>6
replace demdum2EUG=. if dem2==.

gen demdumbothEUG = demdum1EUG*demdum2EUG
*browse year ccodecow abbrev1 ccodecow2 abbrev2 dispnum recip cwinit cwhost1 cwhost2 dem1 polityIV polity2_1 demdum1 personal1 purepers1 hybridpers1 single1 military1  monarch1  interregna chaosPOL threeyr w1 dem2 polityIV2 demdum2 majmaj minmaj majmin  cap_1  cap_2 capshare1 contig ally s_wt_glo s_ld_1 s_ld_2  if year>1945
***dmg: Another variable rename

gen tankerwar=0
replace tankerwar=1 if ccodecow==645 & (year>1983 & year<1988)
replace tankerwar=1 if ccodecow==630 & (year>1983 & year<1989)

***dmg: (cut) gen seizure=0
***dmg: (cut) replace seizure=1 if cwhiact1==15


	*1586 cases total 1946-1999
	*But drop India 1947 and Zimbabwe 1965, 1969 since no regimetype info
***dmg: (cut) drop if year==1947 & abbrev1=="IND"
***dmg: (cut) drop if year==1965 & abbrev1=="ZIM"
***dmg: (cut) drop if year==1969 & abbrev1=="ZIM"

* This is the end of Weeks' exact code.



********************************************** ADD NEW VARIABLES **********************************************************

* Now re-label Weeks' recip variable and merge in the alternatives that we created in the previous do file.

sort ccodecow ccodecow2 year
merge ccodecow ccodecow2 year using "WeeksRecips.dta"
tab _mer
drop _mer
gen float recip_weeks=0
replace recip_weeks=1 if cwhost2>1

* Relabel other variables for merge to work
rename dispnum dispnum_weeks
ren cwinitnm dispnum
replace dispnum=dispnum_weeks if dispnum==.&dispnum_weeks~=.
ren ccodecow ccodea
ren ccodecow2 ccodeb

***dmg: Need to set up data for SideA switches
*gen ccodelow=min(ccodea, ccodeb)
*gen ccodehigh=max(ccodea, ccodeb)
*gen dyad=ccodelow*1000+ccodehigh

*egen dispnummax=max(dispnum), by(dyad year)
*replace dispnum=dispnummax if dispnum==.

gen bilateral_weeks=0
replace bilateral_weeks=1 if cwnumst1==1 & cwnumst2==1
drop cwongo cwongonm cwinit dispnum cwhost1 cwhost2 cwhostd dispnum cworig1 cworig2 cwjoanyi cwjoanyt cwjomidi cwjomidt cwmidnme cwstmo1 cwstday1 cwstyr1 cwstmo2 cwstday2 cwstyr2 cwendmo1 cwenddy1 cwendyr1 cwendmo2 cwenddy2 cwendyr2 cwsidea1 cwsidea2 cwrevis1 cwrevis2 cwrevt11 cwrevt21 cwrevt12 cwrevt22 cwfatal1 cwfatex1 cwfatal2 cwfatex2 cwhiact1 cwhiact2 cwhiactd cwoutcm cwsettle cwfatald cwrecip cwnumst1 cwnumst2
rename year styeara

sort ccodea ccodeb styeara
merge ccodea ccodeb styeara using "Weeks Dyadic MIDs 4.3.dta"   
ren recip recip_mid4
drop if styeara<1946
drop if styeara>1999
tab _mer
drop _mer 

duplicates report ccodea ccodeb dispnum if dispnum~=.
duplicates tag ccodea ccodeb dispnum if dispnum~=., gen(dupes)
tab dupes
list dispnum ccodea ccodeb recip_mid4 recip_weeks if dupes>0&dupes~=.
duplicates drop ccodea ccodeb dispnum if dispnum~=., force
drop dupes

sort ccodea ccodeb styeara
merge ccodea ccodeb styeara  using "Weeks Dyadic MIDs GML ISQ.dta" 
ren recip recip_gml1
drop if styeara<1946
drop if styeara>1999
tab _mer
drop _mer 
duplicates report ccodea ccodeb dispnum if dispnum~=.
duplicates tag ccodea ccodeb dispnum if dispnum~=., gen(dupes)
tab dupes
list dispnum ccodea ccodeb recip_mid4 recip_weeks recip_gml1 if dupes>0&dupes~=.
duplicates drop ccodea ccodeb dispnum if dispnum~=., force
drop dupes

sort ccodea ccodeb styeara
merge ccodea ccodeb styeara  using "Weeks Dyadic MIDs GML 2.1.dta"
ren recip recip_gml2
drop if styeara<1946
drop if styeara>1999
tab _mer
drop _mer 
duplicates report ccodea ccodeb dispnum if dispnum~=.
duplicates tag ccodea ccodeb dispnum if dispnum~=., gen(dupes)
tab dupes
list dispnum ccodea ccodeb recip_mid4 recip_weeks recip_gml1 if dupes>0&dupes~=.
duplicates drop ccodea ccodeb dispnum if dispnum~=., force
drop dupes

*

rename styeara year
rename s_un_glo s_wt_glo

recode gwf_party .=0
recode gwf_personal .=0
recode gwf_military .=0
recode gwf_monarch .=0
recode nondynastic .=0

rename gwf_party single1
rename gwf_personal personal1
rename gwf_military military1
rename gwf_monarch monarch1
rename polity21 polity2_1

sort dispnum

merge dispnum using "WeeksRevCodes.dta"
recode territory .=0
recode policy .=0
recode regime .=0

***
tab _mer


replace dispnum=dispnum_weeks if dispnum==.
******************************************* ANALYSIS **************************************************************************

* We begin be replicating Weeks's results, adding some matrix notation that will allow us to produce figures.

*Weeks - M1
logit recip_weeks demdum1EUG majmaj minmaj majmin capshare1 contig ally s_wt_glo  s_ld_1 s_ld_2 territory policy regime if year>1945&year<2000, robust cluster(dispnum) 
matrix beta = e(b)
matrix cov = e(V)
matrix m1_weeks = J(13,2,.)
matrix coln m1_weeks = coef se
matrix rown m1_weeks = demdum1EUG majmaj minmaj majmin capshare1 contig ally s_wt_glo  s_ld_1 s_ld_2 territory policy regime 
						
foreach i of num 1/13 {
	matrix m1_weeks[`i',1] = beta[1,`i']
	matrix m1_weeks[`i',2] = sqrt(cov[`i',`i'])
}
predict yhat

*Weeks - M2
logit recip_weeks personal1 single1 military1 nondynastic monarch1 majmaj minmaj majmin capshare1 contig ally s_wt_glo s_ld_1 s_ld_2 territory policy regime  if year>1945 & year<2000, robust cluster(dispnum)
matrix beta = e(b)
matrix cov = e(V)
matrix m2_weeks = J(17,2,.)
matrix coln m2_weeks = coef se
matrix rown m2_weeks = personal1 single1 military1 nondynastic  monarch1 majmaj minmaj majmin capshare1 contig ally s_wt_glo s_ld_1 s_ld_2  territory policy regime  
			
foreach i of num 1/17 {
	matrix m2_weeks[`i',1] = beta[1,`i']
	matrix m2_weeks[`i',2] = sqrt(cov[`i',`i'])
}

*Weeks - M3
logit recip_weeks personal1 single1 military1  nondynastic monarch1  majmaj minmaj majmin capshare1 contig ally s_wt_glo s_ld_1 s_ld_2  territory policy regime  if year>1945 & year<2000 & bilateral==1, robust cluster(dispnum)
matrix beta = e(b)
matrix cov = e(V)
matrix m3_weeks = J(17,2,.)
matrix coln m3_weeks = coef se
matrix rown m3_weeks =  personal1 single1 military1  nondynastic monarch1 majmaj minmaj majmin capshare1 contig ally s_wt_glo s_ld_1 s_ld_2  territory policy regime 
foreach i of num 1/17 {
	matrix m3_weeks[`i',1] = beta[1,`i']
	matrix m3_weeks[`i',2] = sqrt(cov[`i',`i'])
}

*Weeks - M4
logit recip_weeks polity2_1 single1 military1 monarch1 nondynastic  majmaj minmaj majmin capshare1 contig ally s_wt_glo  s_ld_1 s_ld_2 territory policy regime  if year>1945 & year<2000 & demdum1==0, robust cluster(dispnum)
matrix beta = e(b)
matrix cov = e(V)
matrix m4_weeks = J(17,2,.)
matrix coln m4_weeks = coef se
matrix rown m4_weeks = polity2_1 single1 military1 monarch1 nondynastic majmaj minmaj majmin capshare1 contig ally s_wt_glo  s_ld_1 s_ld_2  territory policy regime 
foreach i of num 1/17 {
	matrix m4_weeks[`i',1] = beta[1,`i']
	matrix m4_weeks[`i',2] = sqrt(cov[`i',`i'])
}


* Now we run the regressions again using the GML data. 
* We use Version 2.1 of the GML data here because it allows us to make incident-level corrections as Weeks did and because it is the most up-to-date GML data.
* Results using the ISQ article version of the GML data can be seen by sustituting recip_gml1 for recip_gml2.

* In their ISQ article analysis, GML run two sets of models. 
* The first set merely changes the Weeks' recip variable, while the second set also drops observations not in the GML data.
* Here we follow the approach of the second set, both modifying the recip variable and dropping observations based on the GML data.
* We accomplish this simply by not filling in the recip_gml variable for the unmatched observations.
* This approach is most likely to show that using the GML data makes a difference.
 
*GML-M1
logit recip_gml2 demdum1EUG majmaj minmaj majmin capshare1 contig ally s_wt_glo  s_ld_1 s_ld_2 territory policy regime  if year>1945&year<2000, robust cluster(dispnum) 
matrix beta = e(b)
matrix cov = e(V)
matrix m1_gml = J(13,2,.)
matrix coln m1_gml = coef se
matrix rown m1_gml = demdum1EUG majmaj minmaj majmin capshare1 contig ally s_wt_glo  s_ld_1 s_ld_2 territory policy regime 
foreach i of num 1/13 {
	matrix m1_gml[`i',1] = beta[1,`i']
	matrix m1_gml[`i',2] = sqrt(cov[`i',`i'])
}

*GML-M2
logit recip_gml2  personal1 single1 military1 monarch1  nondynastic   majmaj minmaj majmin capshare1 contig ally s_wt_glo s_ld_1 s_ld_2 territory policy regime   if year>1945 & year<2000, robust cluster(dispnum)
matrix beta = e(b)
matrix cov = e(V)
matrix m2_gml = J(17,2,.)
matrix coln m2_gml = coef se
matrix rown m2_gml =  personal1 single1 military1 monarch1 nondynastic  majmaj minmaj majmin capshare1 contig ally s_wt_glo s_ld_1 s_ld_2  territory policy regime
			
foreach i of num 1/17 {
	matrix m2_gml[`i',1] = beta[1,`i']
	matrix m2_gml[`i',2] = sqrt(cov[`i',`i'])
}

*GML-M3
logit recip_gml2  personal1 single1 military1 monarch1  nondynastic  majmaj minmaj majmin capshare1 contig ally s_wt_glo s_ld_1 s_ld_2 territory policy regime   if year>1945 & year<2000 & bilateral==1, robust cluster(dispnum)
matrix beta = e(b)
matrix cov = e(V)
matrix m3_gml = J(17,2,.)
matrix coln m3_gml = coef se
matrix rown m3_gml =  personal1 single1 military1 monarch1  nondynastic majmaj minmaj majmin capshare1 contig ally s_wt_glo s_ld_1 s_ld_2  territory policy regime 
			
foreach i of num 1/17 {
	matrix m3_gml[`i',1] = beta[1,`i']
	matrix m3_gml[`i',2] = sqrt(cov[`i',`i'])
}

*GML-M4
logit recip_gml2 polity2_1 single1 military1 monarch1 nondynastic  majmaj minmaj majmin capshare1 contig ally s_wt_glo  s_ld_1 s_ld_2 territory policy regime   if year>1945 & year<2000 & demdum1==0, robust cluster(dispnum)
matrix beta = e(b)
matrix cov = e(V)
matrix m4_gml = J(17,2,.)
matrix coln m4_gml = coef se
matrix rown m4_gml = polity2_1 single1 military1 monarch1 nondynastic majmaj minmaj majmin capshare1 contig ally s_wt_glo  s_ld_1 s_ld_2 territory policy regime 

foreach i of num 1/17 {
	matrix m4_gml[`i',1] = beta[1,`i']
	matrix m4_gml[`i',2] = sqrt(cov[`i',`i'])
}

* Now we run the regressions once more using the MID 4.3 data

*MID 4-M1
logit recip_mid4 demdum1EUG majmaj minmaj majmin capshare1 contig ally s_wt_glo  s_ld_1 s_ld_2  territory policy regime if year>1945&year<2000, robust cluster(dispnum) 
matrix beta = e(b)
matrix cov = e(V)
matrix m1_mid4 = J(13,2,.)
matrix coln m1_mid4 = coef se
matrix rown m1_mid4 = demdum1EUG majmaj minmaj majmin capshare1 contig ally s_wt_glo  s_ld_1 s_ld_2 territory policy regime  
foreach i of num 1/13 {
	matrix m1_mid4[`i',1] = beta[1,`i']
	matrix m1_mid4[`i',2] = sqrt(cov[`i',`i'])
}

*MID 4-M2
logit recip_mid4  personal1 single1 military1 monarch1  nondynastic majmaj minmaj majmin capshare1 contig ally s_wt_glo s_ld_1 s_ld_2  territory policy regime  if year>1945 & year<2000, robust cluster(dispnum)
matrix beta = e(b)
matrix cov = e(V)
matrix m2_mid4 = J(17,2,.)
matrix coln m2_mid4 = coef se
matrix rown m2_mid4 =   personal1 single1 military1 monarch1  nondynastic majmaj minmaj majmin capshare1 contig ally s_wt_glo s_ld_1 s_ld_2  territory policy regime  
			
foreach i of num 1/17 {
	matrix m2_mid4[`i',1] = beta[1,`i']
	matrix m2_mid4[`i',2] = sqrt(cov[`i',`i'])
}

*MID 4-M3
logit recip_mid4  personal1 single1 military1 monarch1 nondynastic  majmaj minmaj majmin capshare1 contig ally s_wt_glo s_ld_1 s_ld_2 territory policy regime   if year>1945 & year<2000 & bilateral==1, robust cluster(dispnum)
matrix beta = e(b)
matrix cov = e(V)
matrix m3_mid4 = J(17,2,.)
matrix coln m3_mid4 = coef se
matrix rown m3_mid4 =  personal1 single1 military1 monarch1  nondynastic  majmaj minmaj majmin capshare1 contig ally s_wt_glo s_ld_1 s_ld_2  territory policy regime  
			
foreach i of num 1/17 {
	matrix m3_mid4[`i',1] = beta[1,`i']
	matrix m3_mid4[`i',2] = sqrt(cov[`i',`i'])
}

*MID 4-M4
logit recip_mid4 polity2_1 single1 military1 monarch1 nondynastic  majmaj minmaj majmin capshare1 contig ally s_wt_glo  s_ld_1 s_ld_2 territory policy regime   if year>1945 & year<2000 & demdum1==0, robust cluster(dispnum)
matrix beta = e(b)
matrix cov = e(V)
matrix m4_mid4 = J(17,2,.)
matrix coln m4_mid4 = coef se
matrix rown m4_mid4 = polity2_1 single1 military1 monarch1  ///
		majmaj minmaj majmin capshare1 ///
		contig ally s_wt_glo  s_ld_1 s_ld_2  nondynastic  territory policy regime 
		*number 8
foreach i of num 1/17 {
	matrix m4_mid4[`i',1] = beta[1,`i']
	matrix m4_mid4[`i',2] = sqrt(cov[`i',`i'])
}


*labeling vars 
label var demdum1EUG "Democracy"
label var majmaj "Major-Major"
label var minmaj "Minor-Major"
label var majmin "Major-Minor"
label var capshare1 "Initiator Capabilities Share"
label var contig "Contiguity"
label var ally "Ally"
label var s_wt_glo "Alliance Portfolio Similarity"
label var s_ld_1 "Status Quo Evaluation Initiator"
label var s_ld_2 "Status Quo Evaluation Target"

label var personal1 "Personalist"
label var single1 "Single-Party"
label var military1 "Military"
label var monarch1 "Dynastic Monarchy"
label var nondynastic "Non-Dynastic Monarchy"
label var polity2_1 "Democracy Score"

label var territory "Territory"
label var policy "Policy"
label var regime "Regime"

* Make figures

coefplot ///
	(matrix(m1_weeks[.,1]), se(m1_weeks[.,2]) m(smcircle) mlw(medium) msize(medlarge) mfcolor("253 174 97*.4") mlc("253 174 97")  ciop(lcolor("253 174 97" "253 174 97") lwidth(medthick thick) ) label(MID 3)) ///
	(matrix(m1_gml[.,1]), se(m1_gml[.,2])  m(smcircle) mlw(medium) msize(medlarge) mfcolor("215 25 28*.4")  mlc("215 25 28") ciop(lcolor("215 25 28" "215 25 28") lwidth(medthick thick) ) label(GML Data)) ///
	(matrix(m1_mid4[.,1]), se(m1_mid4[.,2])  m(smcircle) mlw(medium) msize(medlarge) mfcolor("31 120 180*.4")  mlc("31 120 180") ciop(lcolor("31 120 180" "31 120 180") lwidth(medthick thick) ) label(MID 4.2)) ///
	,  scheme(s1mono)  ///
	coeflabels()   ///
	legend(col(3) ring()  region(lcolor(none)) size(2)) ///
	xtitle("Coefficient Value" , size(small)) ///
	ytitle(" ", size(small) margin(b=0 l=0 t=0 r=0) ) ///
	subtitle("Nondemocracies are base category" , size(small)) ///
	title("Model 1" , size(medsmall)) ///
	ysca(noline titlegap(0)) ///
	xsca( noextend titlegap(3) range(-2.5,2.5)) ///
	xlabel(-2 -1 0 1 2 , labsize(small) angle(0)  ) ///
	ylabel(,notick   labsize(vsmall)  ) ///
	plotregion(color(gs15) style(none)) ///
	xline(0, lcolor(gray) lpattern(dash)) ///
	ysize(10) xsize() fysize() ///
		graphregion(margin(l=0 r=-2)) ///
	levels(95 90) saving(m1, replace)
	
coefplot ///
	(matrix(m2_weeks[.,1]), se(m2_weeks[.,2]) m(smcircle) mlw(medium) msize(medlarge) mfcolor("253 174 97*.4") mlc("253 174 97")  ciop(lcolor("253 174 97" "253 174 97") lwidth(medthick thick) ) label(MID 3)) ///
	(matrix(m2_gml[.,1]), se(m2_gml[.,2])  m(smcircle) mlw(medium) msize(medlarge) mfcolor("215 25 28*.4")  mlc("215 25 28") ciop(lcolor("215 25 28" "215 25 28") lwidth(medthick thick) ) label(GML Data)) ///
	(matrix(m2_mid4[.,1]), se(m2_mid4[.,2])  m(smcircle) mlw(medium) msize(medlarge) mfcolor("31 120 180*.4")  mlc("31 120 180") ciop(lcolor("31 120 180" "31 120 180") lwidth(medthick thick) ) label(MID 4.2)) ///
	,  scheme(s1mono)  ///
	coeflabels()   ///
	legend(col(3) ring()  region(lcolor(none)) size(2)) ///
	xtitle("Coefficient Value" , size(small)) ///
	ytitle(" ", size(small) margin(b=0 l=0 t=0 r=0) ) ///
	subtitle("Democracies are base category" , size(small)) ///
	title("Model 2" , size(medsmall)) ///
	ysca(noline titlegap(0)) ///
	xsca( noextend titlegap(3) range(-2.5,2.5)) ///
	xlabel(-2 -1 0 1 2 , labsize(small) angle(0)  ) ///
	ylabel(,notick   labsize(vsmall)  ) ///
	plotregion(color(gs15) style(none)) ///
	xline(0, lcolor(gray) lpattern(dash)) ///
	ysize(10) xsize() fysize() ///
		graphregion(margin(l=0 r=-2)) ///
	levels(95 90) saving(m2, replace)
	
coefplot ///
	(matrix(m3_weeks[.,1]), se(m3_weeks[.,2]) m(smcircle) mlw(medium) msize(medlarge) mfcolor("253 174 97*.4") mlc("253 174 97")  ciop(lcolor("253 174 97" "253 174 97") lwidth(medthick thick) ) label(MID 3)) ///
	(matrix(m3_gml[.,1]), se(m3_gml[.,2])  m(smcircle) mlw(medium) msize(medlarge) mfcolor("215 25 28*.4")  mlc("215 25 28") ciop(lcolor("215 25 28" "215 25 28") lwidth(medthick thick) ) label(GML Data)) ///
	(matrix(m3_mid4[.,1]), se(m3_mid4[.,2])  m(smcircle) mlw(medium) msize(medlarge) mfcolor("31 120 180*.4")  mlc("31 120 180") ciop(lcolor("31 120 180" "31 120 180") lwidth(medthick thick) ) label(MID 4.2)) ///
	,  scheme(s1mono)  ///
	coeflabels()   ///
	legend(col(3) ring()  region(lcolor(none)) size(2)) ///
	xtitle("Coefficient Value" , size(small)) ///
	ytitle(" ", size(small) margin(b=0 l=0 t=0 r=0) ) ///
	subtitle("Bilateral disputes only" , size(small)) ///
	title("Model 3" , size(medsmall)) ///
	ysca(noline titlegap(0)) ///
	xsca( noextend titlegap(3) range(-2.5,2.5)) ///
	xlabel(-2 -1 0 1 2 , labsize(small) angle(0)  ) ///
	ylabel(,notick   labsize(vsmall)  ) ///
	plotregion(color(gs15) style(none)) ///
	xline(0, lcolor(gray) lpattern(dash)) ///
	ysize(10) xsize() fysize() ///
		graphregion(margin(l=0 r=-2)) ///
	levels(95 90) saving(m3, replace)
	
coefplot ///
	(matrix(m4_weeks[.,1]), se(m4_weeks[.,2]) m(smcircle) mlw(medium) msize(medlarge) mfcolor("253 174 97*.4") mlc("253 174 97")  ciop(lcolor("253 174 97" "253 174 97") lwidth(medthick thick) ) label(MID 3)) ///
	(matrix(m4_gml[.,1]), se(m4_gml[.,2])  m(smcircle) mlw(medium) msize(medlarge) mfcolor("215 25 28*.4")  mlc("215 25 28") ciop(lcolor("215 25 28" "215 25 28") lwidth(medthick thick) ) label(GML Data)) ///
	(matrix(m4_mid4[.,1]), se(m4_mid4[.,2])  m(smcircle) mlw(medium) msize(medlarge) mfcolor("31 120 180*.4")  mlc("31 120 180") ciop(lcolor("31 120 180" "31 120 180") lwidth(medthick thick) ) label(MID 4.2)) ///
	,  scheme(s1mono)  ///
	coeflabels()   ///
	legend(col(3) ring()  region(lcolor(none)) size(2)) ///
	xtitle("Coefficient Value" , size(small)) ///
	ytitle(" ", size(small) margin(b=0 l=0 t=0 r=0) ) ///
	subtitle("Nondemocracies only;" "personalist base category" , size(small)) ///
	title("Model 4" , size(medsmall)) ///
	ysca(noline titlegap(0)) ///
	xsca( noextend titlegap(3) range(-2.5,2.5)) ///
	xlabel(-2 -1 0 1 2 , labsize(small) angle(0)  ) ///
	ylabel(,notick   labsize(vsmall)  ) ///
	plotregion(color(gs15) style(none)) ///
	xline(0, lcolor(gray) lpattern(dash)) ///
	ysize(10) xsize() fysize() ///
		graphregion(margin(l=0 r=-2)) ///
	levels(95 90)  saving(m4, replace)
	
grc1leg m1.gph m2.gph, rows(1)  scheme(s1mono) 
grc1leg m3.gph m4.gph, rows(1)  scheme(s1mono) 
